package com.sky.controller.user;

import com.sky.dto.OrdersSubmitDTO;
import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import com.sky.vo.OrderSubmitVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "购物车相关接口")
@RequestMapping("/user/shoppingCart")
@Slf4j
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 添加购物车
     *
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        // 1.接收参数
        log.info("接收到参数:{}", shoppingCartDTO);
        // 2.调用service层，实现业务逻辑处理
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        // 3.响应给前端数据
        return Result.success();
    }

    /**
     * 查看购物车
     *
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> list() {
        // 1.调用service层
        List<ShoppingCart> shoppingCarts = shoppingCartService.list();
        // 2.相应数据给前端
        return Result.success(shoppingCarts);
    }

    /**
     * 清空购物车
     *
     * @return
     */
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result clean() {
        // 调用service层
        shoppingCartService.clean();
        // 响应数据
        return Result.success();
    }

    /**
     * 删除购物车中单个商品
     * @return
     */
    @PostMapping("/sub")
    @ApiOperation("删除购物车中多个商品")
    public Result delete(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        // 1.接受参数
        log.info("接收到参数:{}",shoppingCartDTO);
        // 2.调用方法
        shoppingCartService.delete(shoppingCartDTO);
        // 3.响应数据
        return Result.success();
    }


}
